package com.zkyc.framework.common.mapper;

import com.zkyc.framework.common.pojo.Menu;
import com.zkyc.framework.common.pojo.RoleRefMenu;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (RoleRefMenu)表数据库访问层
 *
 * @author wj
 * @since 2022-10-25 11:37:37
 */
@Mapper
public interface RoleRefMenuMapper extends BaseMapper<RoleRefMenu>{

    @Select({"<script>" +
           "  select d.* from system_user_ref_role a,system_website_ref_role b,          " +
            "              system_role_ref_menu c,system_menu d,system_role e          " +
            "               where a.role_id=b.role_id          " +
            "                  and b.website_id=#{websiteId}       " +
            "                  and c.role_id=a.role_id          " +
            "                  and d.id=c.menu_id          " +
            "                  and e.id=a.role_id     " +
            "                  and d.is_delete=0                     " +
            "                  and e.`status`=1         " +
            "                  and d.menu_url is not null "+
            "                  and a.user_id=#{userId}  " +
            "                  order by d.sort      ",
            "</script>"
    })
    List<Menu> getUserWebMenu(@Param("userId") String userId, @Param("websiteId") Integer websiteId);

    @Select({"<script>" +
            " SELECT DISTINCT " +
            " c.*  " +
            " FROM " +
            " system_menu c, " +
            " ( " +
            " SELECT " +
            "  a.id, " +
            "  a.menu_name, " +
            "  a.parent_id  " +
            " FROM " +
            "  system_menu a, " +
            "  system_right b  " +
            " WHERE " +
            "  a.menu_name = b.name  " +
            "  AND a.is_delete = 0  " +
            "  AND b.is_deleted = 0  " +
            "  AND b.id IN (${rightIdList})) d  " +
            "  WHERE " +
            "  c.id = d.parent_id  " +
            "  OR c.id = d.id  " +
            "  OR c.parent_id = d.id " +
            "  and c.is_delete=0",
            "</script>"
    })
    List<Menu> getMenuByRight(@Param("rightIdList") String  rightIdList );


}

